﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AppDataStruct
{
    public class KeyValueCollection
    {
        private string _name = "";
        public string Name
        {
            get { return _name; }
        }

        private Dictionary<string, string> _dicMap = new Dictionary<string,string>();

        public string this[string key]
        {
            get 
            {
                if (_dicMap.ContainsKey(key))
                {
                    return _dicMap[key];
                }
                else
                {
                    throw new Exception("The key is not contained in collection.");
                }
            }
        }


        public void SetKeyVal(string key, string value)
        {
            if (!_dicMap.ContainsKey(key))
            {
                _dicMap.Add(key, value);
            }
            else
            {
                _dicMap[key] = value;
            }
        }

        public void Add(string key, string value)
        {
            if (!_dicMap.ContainsKey(key))
            {
                _dicMap.Add(key, value);
            }
            else
            {
                throw new Exception("The key has existed in collection.");
            }
        }

        public List<KeyValuePair<string, string>> KeyValues
        {
            get 
            { 
                return _dicMap.ToList<KeyValuePair<string, string>>();
            }
        }
    }
}
